package test_junit_shop.ProductStock;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.Random;

/**
 * Created by ZH on 2018/1/25.
 * 门店-添加产品供应商
 */
public class AddProductSupplier {

    private WebDriver wDriver ;
    private static AddProductSupplier addps = new AddProductSupplier();


    public static AddProductSupplier getInstance(){
        return addps;
    }

    public WebDriver getwDriver(){
        return wDriver;
    }

    public void setWebDriver(WebDriver w){
        wDriver = w;
    }

    private static String telephone = "156";

    public void production() throws InterruptedException {
        WebElement firstmenu = wDriver.findElement(By.partialLinkText("产品库存"));
        firstmenu.click();
        WebElement secondmenu = wDriver.findElement(By.partialLinkText("合作商家"));
        secondmenu.click();
        Thread.sleep(2000);
        WebElement thirdmenu = wDriver.findElement(By.partialLinkText("产品供应商"));
        thirdmenu.click();
        Thread.sleep(5000);
    }

    public void createProduction() throws InterruptedException {
        //随机生成电话
        Random r = new Random();
        int i=8;
        while (i-- > 0){
            telephone += r.nextInt(10);
        }
        String no = telephone.substring(7,11);

        wDriver.switchTo().frame(wDriver.findElement(By.xpath("//*[@id='content-main']/iframe[2]")));
        WebElement addbtn = wDriver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[1]/p/button[1]"));
        addbtn.click();
        Thread.sleep(5000);
        wDriver.switchTo().frame(wDriver.findElement(By.xpath("/html/body/div[4]/div[2]/iframe")));
        WebElement phone = wDriver.findElement(By.id("cellPhone"));
//        phone.sendKeys("15624587922");
        phone.sendKeys(telephone);
        WebElement companyName = wDriver.findElement(By.id("companyName"));
        companyName.sendKeys("皮皮公司"+no);
        WebElement email = wDriver.findElement(By.id("email"));
        email.sendKeys("64225@qq.com");
        WebElement alias = wDriver.findElement(By.id("alias"));
        alias.sendKeys("Mr.pi"+no);
        WebElement businessPhone = wDriver.findElement(By.id("businessPhone"));
        businessPhone.sendKeys("110");
        WebElement certificationNo = wDriver.findElement(By.id("certificationNo"));
        certificationNo.sendKeys("632811199525262222");
        WebElement subbtn = wDriver.findElement(By.id("sub"));
        subbtn.click();
        Thread.sleep(5000);
        WebElement confirmbtn = wDriver.findElement(By.xpath("/html/body/div[4]/div[3]/a[1]"));
        confirmbtn.click();
    }

}
